[Unit]
{% if db_role == 'controller' %}
Description=Apache Kafka Server (controller)
{% elif db_role == 'broker' %}
Description=Apache Kafka server (broker)
{% elif db_role == 'controller,broker' %}
Description=Apache Kafka server (kafka)
{%- endif %}

Documentation=http://kafka.apache.org/documentation.html  
Requires=network.target
After=network.target

[Service]
Type=forking
User=kafka
Group=kafka
Environment="JAVA_HOME=/usr/local/java"

{% if db_role == 'controller' %}
ExecStart={{ kafka.install_dir }}kafka/bin/kafka-server-start-sasl.sh -daemon {{ kafka.install_dir }}kafka/config/kraft/controller.properties
{% elif db_role == 'broker' %}
ExecStart={{ kafka.install_dir }}kafka/bin/kafka-server-start-sasl.sh -daemon {{ kafka.install_dir }}kafka/config/kraft/broker.properties
{% elif 'controller,broker' in db_role %}
ExecStart={{ kafka.install_dir }}kafka/bin/kafka-server-start-sasl.sh -daemon {{ kafka.install_dir }}kafka/config/kraft/server.properties
{%- endif %}

ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target